package cn.ds.assets.module.assets.dal.mysql.metadataJobCollect;

import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDate;

import cn.ds.assets.framework.common.pojo.PageResult;
import cn.ds.assets.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ds.assets.framework.mybatis.core.mapper.BaseMapperX;
import cn.ds.assets.module.assets.dal.dataobject.metadataJobCollect.BaseMetadataJobCollectDO;
import org.apache.ibatis.annotations.Mapper;
import cn.ds.assets.module.assets.controller.admin.metadataJobCollect.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 元数据管理-元数据采集作业 Mapper
 *
 * @author admin
 */
@Mapper
public interface BaseMetadataJobCollectMapper extends BaseMapperX<BaseMetadataJobCollectDO> {

    default PageResult<BaseMetadataJobCollectDO> selectPage(BaseMetadataJobCollectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BaseMetadataJobCollectDO>()
                .likeIfPresent(BaseMetadataJobCollectDO::getJobName, reqVO.getJobName())
                .eqIfPresent(BaseMetadataJobCollectDO::getSourceId, reqVO.getSourceId())
                .eqIfPresent(BaseMetadataJobCollectDO::getCron, reqVO.getCron())
                .eqIfPresent(BaseMetadataJobCollectDO::getTimeout, reqVO.getTimeout())
                .betweenIfPresent(BaseMetadataJobCollectDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(BaseMetadataJobCollectDO::getEndTime, reqVO.getEndTime())
                .betweenIfPresent(BaseMetadataJobCollectDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseMetadataJobCollectDO::getJobCode, reqVO.getJobCode())
                .eqIfPresent(BaseMetadataJobCollectDO::getDataForm, reqVO.getDataForm())
                .eqIfPresent(BaseMetadataJobCollectDO::getDataTable, reqVO.getDataTable())
                .eqIfPresent(BaseMetadataJobCollectDO::getProjectId, reqVO.getProjectId())
                .eqIfPresent(BaseMetadataJobCollectDO::getDataObj, reqVO.getDataObj())
                .inIfPresent(BaseMetadataJobCollectDO::getId,reqVO.getIds())
                .orderByDesc(BaseMetadataJobCollectDO::getId));
    }

    default List<BaseMetadataJobCollectDO> selectList(BaseMetadataJobCollectExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BaseMetadataJobCollectDO>()
                .likeIfPresent(BaseMetadataJobCollectDO::getJobName, reqVO.getJobName())
                .eqIfPresent(BaseMetadataJobCollectDO::getSourceId, reqVO.getSourceId())
                .eqIfPresent(BaseMetadataJobCollectDO::getCron, reqVO.getCron())
                .eqIfPresent(BaseMetadataJobCollectDO::getTimeout, reqVO.getTimeout())
                .betweenIfPresent(BaseMetadataJobCollectDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(BaseMetadataJobCollectDO::getEndTime, reqVO.getEndTime())
                .betweenIfPresent(BaseMetadataJobCollectDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseMetadataJobCollectDO::getJobCode, reqVO.getJobCode())
                .eqIfPresent(BaseMetadataJobCollectDO::getDataForm, reqVO.getDataForm())
                .eqIfPresent(BaseMetadataJobCollectDO::getDataTable, reqVO.getDataTable())
                .eqIfPresent(BaseMetadataJobCollectDO::getProjectId, reqVO.getProjectId())
                .eqIfPresent(BaseMetadataJobCollectDO::getDataObj, reqVO.getDataObj())
                .inIfPresent(BaseMetadataJobCollectDO::getId,reqVO.getIds())
                .orderByDesc(BaseMetadataJobCollectDO::getId));
    }

    @Update("UPDATE assets_metadata_job_collect SET deleted = 1, update_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
}
